package com.ye.spring.pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class Demo implements BeanPostProcessor {

    private Integer id;

    public Demo() {
        System.out.println("实例化");
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        System.out.println("依赖注入");
        this.id = id;
    }

    @Override
    public String toString() {
        return "Demo{" +
                "id=" + id +
                '}';
    }

    public void initMethod() {
        System.out.println("初始化");
    }

    public void destroyMethod() {
        System.out.println("销毁");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("初始化前");
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("初始化后");
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
